#include <REGX52.H>
sbit ONEWIRE_DQ=P3^7;
unsigned char ONEWIRE_INIT()
{
	unsigned char i;
	unsigned char ack;
	ONEWIRE_DQ=1;
	ONEWIRE_DQ=0;
	i = 247;while (--i);
	ONEWIRE_DQ=1;
	i = 32;while (--i);
	ack=ONEWIRE_DQ;
	i = 247;while (--i);
	return ack;
}
void ONEWIRE_SEND(unsigned char BIT)
{ 
	unsigned char i;
	ONEWIRE_DQ=0;
	i = 4;while (--i);
	ONEWIRE_DQ=BIT;  
	i = 24;while (--i);
	ONEWIRE_DQ=1;
}
unsigned char ONEWIRE_RECIVE()
{
	unsigned char BIT;
	unsigned char i;
	
	ONEWIRE_DQ=0;
	i = 2;while (--i);
	ONEWIRE_DQ=1;
	i = 2;while (--i);
	BIT=ONEWIRE_DQ;
	i = 24;while (--i);
	return BIT;
}
void ONEWIRE_SENDBITY(unsigned char BITY)
{
	unsigned char i=0;
	for(i=0;i<8;i++)
	{
		ONEWIRE_SEND(BITY&(0x01<<i));
	}
}
unsigned char ONEWIRE_RECIVEBITY()
{
	unsigned char i;
	unsigned char BITY=0x00;
	for(i=0;i<8;i++)
	{
		if(ONEWIRE_RECIVE())
		{
			BITY|=(0x01<<i);
		}
	}
	return BITY;
}